package cn.appsys.controller;

import java.io.FileOutputStream;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import cn.appsys.biz.CategoryBiz;
import cn.appsys.biz.DictionaryBiz;
import cn.appsys.biz.InfoBiz;
import cn.appsys.biz.VersionBiz;
import cn.appsys.entity.AppCategory;
import cn.appsys.entity.AppInfo;
import cn.appsys.entity.AppVersion;
import cn.appsys.entity.DataDictionary;
import cn.appsys.entity.DevUser;


@Controller
public class AppInfoController {
	@Autowired
	private CategoryBiz categoryBiz;
	
	@Autowired
	private InfoBiz infoBiz;
	
	@Autowired
	private DictionaryBiz dictionaryBiz;
	
	@Autowired
	private VersionBiz versionBiz;

	@RequestMapping("/appupdate")
	public String appupdate(Model model,int id){
		List<DataDictionary> flatformList=dictionaryBiz.getByFlatform();
		AppInfo appInfo=infoBiz.getByIdAppInfo(id);
		List<DataDictionary> statusList=dictionaryBiz.getByStatus();
List<AppCategory> listone =categoryBiz.getAllCategory();
		
		model.addAttribute("listone",listone);
		model.addAttribute("appInfo",appInfo);
		
		model.addAttribute("flatformList", flatformList);
		model.addAttribute("statusList", statusList);
		
		return "appupdate";
	}
	
	@RequestMapping("/doappupdate")
	public String doappupdate(AppInfo appInfo){
		appInfo.setModifyDate(new Date());
		System.out.println(appInfo);
		int temp = infoBiz.updateAppInfo(appInfo);
		System.out.println(temp);
		return "redirect:AppInfo";
	}
	
	@RequestMapping("/appupdateandaudit")
	public String appupdateandaudit(AppInfo appInfo){
		appInfo.setModifyDate(new Date());
		appInfo.setStatus(1);
		int temp = infoBiz.updateAppInfo(appInfo);
		System.out.println(temp);
		return "redirect:AppInfo";
	}
	@RequestMapping("/appview")
	public String appview(int id,Model model){
		List<AppVersion> versionList=versionBiz.getByIdVersion(id);
		
		AppInfo appInfo=infoBiz.getByIdAppInfo(id);
		
		String versionName=dictionaryBiz.getByIdVersionStatus(appInfo.getStatus());
		List<AppCategory> listone =categoryBiz.getAllCategory();
		
		model.addAttribute("listone",listone);
		
		model.addAttribute("appInfo", appInfo);
		model.addAttribute("versionName", versionName);
		model.addAttribute("versionList", versionList);
		return "appview";
	}
}
